package net.huashitong.supervision.task.dao;

import com.sirdc.modules.core.dao.GenericQuery;
import com.sirdc.modules.core.dao.StringDao;
import net.huashitong.supervision.task.entity.DeptTaskRanksEntity;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class DeptTaskRanksDao extends StringDao<DeptTaskRanksEntity> {

    /**
     * 根据主任务Id拿到 排名DeptTaskRanks
     * @param taskMainId
     * @return
     */
      public List<DeptTaskRanksEntity> getListDeptRank(String taskMainId,String timeRound)
      {
          GenericQuery query = createQuery("obj");
          query.append("and obj.mainTaskId=:mainTaskId").setParam("mainTaskId",taskMainId);
          query.append(" and obj.timeRound=:timeRound").setParam("timeRound",timeRound);
          query.setOrder("deptRank",GenericQuery.ASC);
          return query.listResult();
      }

    public DeptTaskRanksEntity getOwnRank(String deptId,String timeRound,String taskMainId)
    {
        GenericQuery query = createQuery("obj");
        query.append(" and obj.deptId=:deptId").setParam("deptId",deptId);
        query.append(" and obj.mainTaskId=:mainTaskId").setParam("mainTaskId",taskMainId);

        query.append(" and obj.timeRound=:timeRound").setParam("timeRound",timeRound);
        query.setOrder("deptRank",GenericQuery.ASC);
        return query.singleResult();
    }

    public List<DeptTaskRanksEntity> queryRankByMainId(String taskMainId)
    {
        GenericQuery query = createQuery("obj");
        query.append("and obj.mainTaskId=:mainTaskId").setParam("mainTaskId",taskMainId);
       // query.setOrder("timeRound",GenericQuery.ASC);
        return  query.listResult();
    }

}
